

package edu.spec.sys.web;

import org.springframework.core.io.ClassPathResource;

import java.util.Properties;

public class PropertyHolder {
    private static Properties props = new Properties();

    static {
        reload();
    }

    public static Properties getProperties() {
        return props;
    }

    public static void reload() {
        String developConfig="/system.properties";
        ClassPathResource cr = null;
        try{
            cr = new ClassPathResource(developConfig);
            props.load(cr.getInputStream());
        }catch(Exception e){
        }

        String extendPropertyFiles = props.getProperty("extend.property.files");
        if(extendPropertyFiles!=null && !"".equals(extendPropertyFiles.trim())){
            String[] files=extendPropertyFiles.trim().split(",");
            for(String file : files){
                try{
                    cr = new ClassPathResource(file);
                    props.load(cr.getInputStream());
                }catch(Exception e){
                }
            }
        }
        for(String propertyName : props.stringPropertyNames()){
        }
    }

    public static boolean getBooleanProperty(String name) {
        String value = props.getProperty(name);
        return "true".equals(value);
    }

    public static int getIntProperty(String name) {
        String value = props.getProperty(name);

        return Integer.parseInt(value);
    }

    public static String getProperty(String name) {
        String value = props.getProperty(name);

        return value;
    }

    public static void setProperty(String name, String value) {
        props.setProperty(name, value);
    }
}